<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>购物车</title>
		<link rel="stylesheet" href="__PUBLIC__/home/css/chushihua.css" />
		<link rel="stylesheet" href="__PUBLIC__/home/css/gouwuche.css" />
		<script src="__PUBLIC__/home/js/jquery-1.8.3.min.js"></script>
		<script src="__PUBLIC__/home/js/gouwuche.js"></script>
		<script src="__PUBLIC__/home/js/Calculation.js"></script>
	</head>
	<body>

<include file="Public:header_zc" />
<!--最大  div-->
<div class="content">
<!--购物车   标题-->

<div class="gouwuchebt">
<div class="logo">
	<a href="{:U('Index/index?key=')}{$appkey}"><img src="{$think_path}{$shop_logo.img}" alt="" /></a>
</div>	
<div class="hyzc"><h1>购物车</h1></div>

</div>
<!--购物车   end-->

<!--全部商品   标题-->
<div class="quanbu">
	<span>全部商品</span>
	<form class="form-search" action="{:U('Product/index?key=')}{$appkey}" method="post" >
	<div class="gouwuche_sousuo">
	
		<input type="text" name="keywords" />
		<button type="submit"  name="sub">确定</button>
	</div>
	</form>
</div>

<!--全部商品  end-->

<!--全选-->
<script> 
var selAll = document.getElementById("selAll"); 
function selectAll(){ 
  var obj = document.getElementsByName("newslist"); 
  if(document.getElementById("selAll").checked == false){ 
  for(var i=0; i<obj.length; i++){ 
    obj[i].checked=false; 
     } 
  }else{ 
  for(var i=0; i<obj.length; i++){	  
    obj[i].checked=true; 
     }	
  } 
 	GetCount();
}  
function setSelectAll(){ 
var obj=document.getElementsByName("newslist"); 
var count = obj.length; 
var selectCount = 0; 
for(var i = 0; i < count; i++){ 
if(obj[i].checked == true){ 
selectCount++;	
  } 
} 
if(count == selectCount){	
document.all.selAll.checked = true; 
} 
else{ 
document.all.selAll.checked = false; 
  } 
  	GetCount();
} 
</script> 
<!--全选-->
<!--全部商品  选购-->
<div class="quanbushangpin">
	<div class="quanxuan_text">
		<ul>
			<li class="quanxuan"><input type="checkbox" id="selAll" onclick="selectAll();"/>&nbsp;&nbsp;全选</li>
			<li class="shangpin">商品</li> 
			<li>单价（元）</li>
			<li>数量</li>
			<li>小计（元）</li>
			<li>操作</li>
		</ul>
	</div>
	
	<volist name="sval" id="shipin">
	<div class="shangpin_one">
	
		<div class="shangjia"><input type="checkbox" name="newslists" class="select" onclick="setSelectAll();"/>&nbsp;&nbsp;<span>商家：<a href="{:U('Shopping/shopDetail',array('id'=>$shipin['id'],'key'=>$appkey))}">{$shipin.name}</a></span>
		<a target="_blank" href="http://amos.alicdn.com/msg.aw?v=2&uid={$shipin.wangwang}&site=cnalichn&s=11&charset=UTF-8" >
		<img border="0" src="http://amos.alicdn.com/online.aw?v=2&uid={$shipin.wangwang}&site=cnalichn&s=11&charset=UTF-8" style="vertical-align:text-top;" alt="点击这里给我发消息" /></a>
		</div>
		<volist name="shipin['slist']" id="shopin">
		<div class="shangpin_one_top" id="gwc_tb">
		  <ul>
		  	<li class="one"><input type="checkbox" value="1" class="xuan" name="newslist" id="newslist-{$shopin.id}" onclick="setSelectAll();"/></li>
		  	<li class="two"><a href="{:U('Product/xi',array('id'=>$shopin['proid'],'key'=>$appkey))}"><img src="{$think_path}{$shopin.photo_x}" alt="" width="145" height="122"/></a></li>
		  	<li class="three"><a href="{:U('Product/xi',array('id'=>$shopin['proid'],'key'=>$appkey))}">{$shopin.name}</a><p>{$shopin.gname}<volist name="shopin['buf']" id="shai">&nbsp;{$shai.name}</volist></p></li>
		  	<li class="four">￥ <if condition="$shopin.gid neq 0 "> {$shopin.price}<else />{$shopin.price_yh} </if></li>
		  	<li><div class="jiajian">
 			<input type="button" class="jiana" id="jian{$shopin.id}" value="-" data-num="{$shopin['pnum']}"/>
            <input type="text" class="numa" id="num{$shopin.id}" value="{$shopin.num}"  readonly="readonly"/>
            <input type="button" class="adda" id="add{$shopin.id}" value="+" data-num="{$shopin['pnum']}"/></div>
		  	</li>
		  	<li><label id="total{$shopin.id}" class="tot" style="color:#ff5500;font-size:14px; font-weight:bold;"><if condition="$shopin.gid neq '' "> {$shopin.price}<else /> {$shopin.price_yh}</if></label></li>
		  	<li class="five"><p><a href="{:U('Shopping/delete',array('id'=>$shopin['id'],'key'=>$appkey))}" class="remove_btn">删除</a></p><p><a href="{:U('Shopping/remove',array('id'=>$shopin['proid'],'key'=>$appkey))}">移到我的关注</a></p></li>
		  </ul>
	    </div>
	    <script type="text/javascript">
		$(function () {
			var t = $("#num{$shopin.id}");
			var id ={$shopin.id};
			$("#add{$shopin.id}").click(function () {
				var _inputNum = parseInt($(this).prev().val());
				var _allNum = parseInt($(this).attr('data-num'));
				setTotal(); GetCount();
				if(_inputNum >= _allNum) {
					alert('超过库存!');
					return false;
				}
				t.val(parseInt(t.val()) + 1)
				$.post("{:U('Shopping/numadd',array('key'=>$appkey))}",{"num":t.val(),"id":id});
			})
			$("#jian{$shopin.id}").click(function () {
				if((t.val())>=2){
				t.val(parseInt(t.val()) - 1)
				}
				setTotal(); GetCount();
				$.post("{:U('Shopping/numsubtract',array('key'=>$appkey))}",{"num":t.val(),"id":id});
			})
			function setTotal() {
	
				$("#total{$shopin.id}").html((parseInt(t.val()) *  <if condition="$shopin.gid neq 0 "> {$shopin.price}<else /> {$shopin.price_yh}</if>).toFixed(2));
				$("#newslist-{$shopin.id}").val(parseInt(t.val()) *  <if condition="$shopin.gid neq 0 "> {$shopin.price}<else /> {$shopin.price_yh}</if>);
			}
			setTotal();
		})
	</script>
	    </volist>
	</div>
	</volist>
	
	<!--商品1  的价钱-->
	
 
</div>	
<div class="jiesuan_text">
		<ul>
			<li class="shanchu"><input id="Checkbox1" type="checkbox" class="allselect"/></li>
			<li class="yidong" id="del_All">删除选中的商品</li>					
			<li class="yidong" id="d_remove">移动到我的关注</li>
			<li class="zongjia">总价（不含运费）：<span>￥ </span><span style=" color:#ff5500;"><label id="zong1" style="color:#ff5500;font-size:14px; font-weight:bold;">0</label></span></li>
			<li class="jiesuan"><span id="jz1">结算</span><a   style=" display:none;"  class="jz2" id="jz2" onclick="voids();">结算</a></li>
		</ul>
	</div>	
 <script type="text/javascript">
       function voids(){
	   //alert('aaa');
	         var adIds = "";  
		        $("input[name=newslist]:checked").each(function(i){  
		        	var arr = $(this).attr('id').split('-');
		            if(0==i){  
		                adIds = arr[1];  
		            }else{  
		                adIds += (","+arr[1]);  
		            }
                 }); 
				 $.post("{:U('Shopping/dianpu',array('key'=>$appkey))}",{"id":adIds},function(data){
				 if(data=='ok'){
				 
				 window.location.href="{:U('Product/payments',array('key'=>$appkey))}&id="+adIds;
				 }else if(data==0){
				    alert('价格为0的产品不能和其它产品(价格大于0)一起购买');
				 }else{
				    alert('只能购买同一商家的商品');
				 }
				
			});
				 //window.location.href="__APP__/Product/payments/id/"+adIds;
	   }
		$(function () {	
		   
			$("#del_All").click(function(){
				var adIds = "";  
		        $("input[name=newslist]:checked").each(function(i){  
		        	var arr = $(this).attr('id').split('-');
		            if(0==i){  
		                adIds = arr[1];  
		            }else{  
		                adIds += (","+arr[1]);  
		            }  
		        });  
		       // alert(adIds);
				$.post("{:U('Shopping/qdelete',array('key'=>$appkey))}",{"id":adIds},function(data){
				alert(data);
				if(data!=''){
					window.location.reload();
				}
			});
			
			});
		    $("#d_remove").click(function(){
				var adIds = "";  
		        $("input[name=newslist]:checked").each(function(i){  
		        	var arr = $(this).attr('id').split('-');
		            if(0==i){  
		                adIds = arr[1];  
		            }else{  
		                adIds += (","+arr[1]);  
		            }  
		        });  
		       // alert(adIds);
				$.post("{:U('Shopping/dremove',array('key'=>$appkey))}",{"id":adIds},function(datas){
				alert(datas);
				if(datas!=''){
					window.location.reload();
				}
			});
			
			});
		})
</script>
<!--全部商品  选购  end-->

<!--结尾-->

	
	<include file="Public:footer" />

	</div>		
	</body>
</html>
